package com.ctrip.corp.obt.shard.loader;


import com.ctrip.corp.obt.generic.utils.ExceptionUtils;
import com.ctrip.corp.obt.shard.constants.SourceLoadMode;
import com.ctrip.corp.obt.shard.manager.DataShardSourceManager;
import lombok.extern.slf4j.Slf4j;

import java.util.Set;

/**
 * @author marco.zheng
 * @version 1.0
 * @date 2022/01/14
 * @desc single数据分片加载器
 * @see
 * @since 1.0
 */
@Slf4j
public class SingleShardSourceLoader extends AbstractShardSourceLoader {

    public SingleShardSourceLoader(DataShardSourceManager dataShardSourceManager) {
        super(dataShardSourceManager);
    }

    /**
     * Startup加载
     *
     * @return
     */
    @Override
    public void loadOnStartup() {
        getDataShardSourceManager().initDataSource();
        log.info("Startup loading shard source, source load mode:[{}]", SourceLoadMode.SINGLE);
    }

    @Override
    public void refresh(String tenantId) {

    }

    /**
     * 指定分组加载(后期客户量大，每个pod只能按照策略加载有限的ds)
     * 可通过control plane进行分配
     *
     * @return
     */
    @Override
    public Set<String> loadBySources(Set<String> tenantIds) {
        throw ExceptionUtils.mpe("Single sourceLoadMode do not allow load by source");
    }

}
